package com.scopionstudio.housemusic.parser;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;

public class ParserJson {
	String TAG = "JSONParse";
	static InputStream is = null;
	static JSONObject jObj = null;
	static String json = "";

	// constructor
	public ParserJson() {

	}

	public String getJson(String url) {
		String jsonString = null;
		HttpURLConnection linkConnection = null;
		try {
			URL linkURL = new URL(url);
			linkConnection = (HttpURLConnection) linkURL.openConnection();
			int responseCode = linkConnection.getResponseCode();
			if (responseCode == HttpURLConnection.HTTP_OK) {
				InputStream linkinStream = linkConnection.getInputStream();
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				int j = 0;
				while ((j = linkinStream.read()) != -1) {
					baos.write(j);
				}
				byte[] data = baos.toByteArray();
				jsonString = new String(data);
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (linkConnection != null) {
				linkConnection.disconnect();
			}
		}

		return jsonString;
	}
}
